package com.lxwm.bag;

import java.sql.SQLException;
import java.util.ArrayList;

import com.administrators.bag.Administrators;
import com.wzsck.util.DBManager;
import com.wzsck.util.QueryDataResult;
//wzs_leaveamessage
public class LXWMManager {
	public ArrayList<lxwm> query(int page, int limit) {
		ArrayList<lxwm> list = new ArrayList<lxwm>();
		String sql = "select * from wzs_leaveamessage";
		if (page != 0 && limit != 0) {
			sql += " limit " + (page - 1) * limit + "," + limit;
		}
		QueryDataResult qdr = DBManager.executeQuery(sql);
		if (qdr.rs != null) {
			try {
				while (qdr.rs.next()) {					
					int id = qdr.rs.getInt("id");		
					String name = qdr.rs.getString("name");
					String phonenumber=qdr.rs.getString("phonenumber");
					String leaveamessage=qdr.rs.getString("leaveamessage");
					String mailbox= qdr.rs.getString("mailbox");		
					lxwm b = new lxwm(id,name,phonenumber,leaveamessage,mailbox);
					list.add(b);
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		qdr.close();
		return list;
	}
	 public ArrayList<Administrators> mhcx(String ss){//把东西存到动态数组里面
			ArrayList<Administrators> list = new ArrayList<Administrators>();
			String sql= "SELECT * from wzs_administrators  LIKE '"+ss+"'";//from 表名 where列名
			QueryDataResult qdr =DBManager.executeQuery(sql);
			if (qdr.rs!=null){
				try {
					while (qdr.rs.next()){
						String id=qdr.rs.getString("id");
						String name=qdr.rs.getString("name");//书名							
						String password=qdr.rs.getString("password");//价格
						Administrators x= new Administrators(id,name,password);
						list.add(x);
					}
				} catch (SQLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return list;
		}
	//============================
	//add
			public int add( String name,String phonenumber, String leaveamessage,String mailbox) {
				String sql = String.format(
						"insert into wzs_leaveamessage(`name`,`phonenumber`,`leaveamessage`,`mailbox`) values('%s','%s','%s',%s)",name, phonenumber, leaveamessage, mailbox);
				
				System.out.print(sql);
				int i = DBManager.executeUpdate(sql);
				return i;

			}
			public int del(int id) {
				String sql = "delete from wzs_leaveamessage where id = " + id;
				int i = DBManager.executeUpdate(sql);
				return i;
			}
	//===============================================================		
	 public int count() {//count查非空
	 		String sql="select count(*) from wzs_leaveamessage";//换表名
	 		QueryDataResult qdr=DBManager.executeQuery(sql);
	 		if (qdr.rs!=null) {
	 			try {
	 				while (qdr.rs.next()) {
	 					int count =qdr.rs.getInt("count(*)");
	 					return count;
	 				}
	 			} catch (SQLException e) {
	 				// TODO Auto-generated catch block
	 				e.printStackTrace();
	 			}
	 		}
	 		return 0;
	 	}
}
